package com.hrt.manage.access.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.RoleAccess;
import com.hrt.bean.ViewResource;
import com.hrt.manage.access.dao.AccessDao;

@Repository
public class AccessDaoImpl extends BaseDaoImpl<RoleAccess> implements AccessDao {

	@Override
	public List<RoleAccess> queryAccByRole(Long roleId) {
		List<RoleAccess> access = new ArrayList<RoleAccess>();
		String hql = "select acc from RoleAccess acc where acc.isdelete=0 and acc. roleId="
				+ roleId + "";

		access = this.getHibernateTemplate().find(hql);
		return access;
	}

	@Override
	public List<ViewResource> queryAccByScope(Long roleId, Integer scope) {
		List<ViewResource> access = new ArrayList<ViewResource>();
		String hql = "select vr from ViewResource vr where vr.id  in(select acc.resId from RoleAccess acc where acc.isdelete=0 and acc. roleId="
				+ roleId + " ) and vr.scope='"+scope+"' and vr.isdelete=0";

		access = this.getHibernateTemplate().find(hql);
		return access;
	}

}
